package com.swz.dcrm.adpter;

import android.content.Context;
import android.graphics.Color;

import com.swz.dcrm.R;
import com.swz.dcrm.base.ViewHolder;

import java.util.List;

public class CarColorAdapter extends CustomAdapter<String>{

    public CarColorAdapter(Context context, List<String> datas) {
        super(context, R.layout.item_car_param_color, datas);
    }

    @Override
    protected void convert(ViewHolder holder, String s, int position) {
        String[] strings=s.split(":");
        holder.setText(R.id.tv_color,strings[0]);
        if(position==getCurrentClickPosition()){
            if(strings.length==1){
                holder.getView(R.id.tv_color).setBackgroundColor(mContext.getResources().getColor(R.color.gray_c0c4cc));
            }else {
                holder.getView(R.id.tv_color).setBackgroundColor(Color.parseColor(strings[1]));
            }

        }else {
            holder.getView(R.id.tv_color).setBackgroundColor(Color.parseColor("#f5f7f8"));
        }
        holder.itemView.setOnClickListener(v -> {
            setCurrentClickPosition(position);
            notifyDataSetChanged();
            if(onClickListener!=null){
                onClickListener.onItemClick(s);
            }

        });
    }
}
